#import "WeatherViewController.h"
#import "WeatherResponse.h"
#import "ProvinceAndCity.h"
#import "LocationViewController.h"
#import "CityCRViewController.h"
#import "WeatherResponse.h"
#import "ProvinceAndCity.h"
@implementation WeatherViewController
@synthesize _tableView;
@synthesize response;
@synthesize indicator;
- (void)dealloc {
    [super dealloc];
}

-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section{
	if (response) {
		return [response.days count];
	}
	return 0;
}

-(void) viewWillAppear:(BOOL)animated{
	NSString *value = [[NSString alloc] initWithFormat: @"%@_%@", response.provinceName, response.cityName];
	[[NSUserDefaults standardUserDefaults] setValue: value forKey: kLastCheck];
	[[NSUserDefaults standardUserDefaults] synchronize];
	[value release];
}

-(UITableViewCell *) tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
	static NSString *WEEK_ROW_ID = @"WEEK_ROW_ID";
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: WEEK_ROW_ID];
	if (!cell) {
		cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: WEEK_ROW_ID];
	}
		Day *day = [response.days objectAtIndex: [indexPath row]];
		if(day){
			cell.textLabel.font = [UIFont systemFontOfSize: 15];
			cell.textLabel.text = [day toString];					 
			cell.imageView.image = [UIImage imageNamed: day.image];
			cell.detailTextLabel.text = day.wind;
		}
	return cell;
}


#pragma mark self methods
-(void) reloadWeather{
	[indicator stopAnimating];
	//	IBOutlet UILabel *tempField;
	self.navigationItem.title = response.cityName;
	updateTimeField.text = response.updateTime;
	windField.text = response.wind;
	humiField.text = response.humi;
	tempField.text = response.temp;
	NSString *bigImageName = [[NSString alloc] initWithFormat:@"a_%@",response.mainImage];
	imageView.image = [UIImage imageNamed: bigImageName];
	[bigImageName release];
	[_tableView reloadData];
}
@end
